//
//  EVSearchBar.h
//  EVClub
//
//  Created by Sam on 13-03-19.
//  Copyright (c) 2013 xunlei.com. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol EVSearchBarDelegate;

typedef enum{
    SearchStyleWhite = 0,
    SearchStyleGray,
    SearchStyleBlue,
    SearchStyleNone
}SearchStyle;

@interface EVSearchBar : UIView<UITextFieldDelegate>

+ (EVSearchBar* )loadSearBarWithFrame:(CGRect)frame;
+ (EVSearchBar *)loadSearBarWithFrame:(CGRect)frame style:(SearchStyle)style;

- (void)showCancelButton:(BOOL)flag;
- (void)showCancelButton:(BOOL)flag animated:(BOOL)animated;
- (IBAction)cancelButtonAction:(id)sender;

@property(nonatomic,weak)IBOutlet UITextField *textField;
@property(nonatomic,weak) id<EVSearchBarDelegate> delegate;
@property(nonatomic,copy) NSString *text;
@property(nonatomic,copy) NSString *placeholder;
@property(nonatomic,copy) NSString *alertMessage;
@property(nonatomic,strong) UIImageView *backgroundView;
@property(nonatomic,strong) UIImage *backgroundImage;
@property(nonatomic,assign) NSInteger resultCount; //搜索框右侧显示的结果数量，-1时不显示
@property(nonatomic,assign) NSInteger maxLength; //最大输入字数，为0时不限制
@property(nonatomic,assign) BOOL autoShowCancelButton;//默认:YES 获取第一响应者时自动显示“取消”按钮
@property (nonatomic, assign) BOOL useForTopicSeach;

- (void)textChecking;
- (void)setButtonTitleColor:(UIColor *)color;
- (void)setButtonBackgroundColor:(UIColor *)color;

@end


@protocol EVSearchBarDelegate <NSObject>

@optional

- (BOOL)searchBarShouldBeginEditingTextField:(EVSearchBar *)searchBar;
- (void)searchBarDidBeginEditingTextField:(EVSearchBar *)searchBar;
- (void)searchBarShouldEndEditingTextField:(EVSearchBar *)searchBar;
- (void)searchBarDidEndEditingTextField:(EVSearchBar *)searchBar;
- (void)searchBarShouldReturnTextField:(EVSearchBar*)searchBar;
- (void)searchBarShouldClearTextField:(EVSearchBar*)searchBar;
- (void)searchBar:(EVSearchBar *)searchBar textDidChange:(NSString *)searchText;   // called when text changes
- (void)searchBarCancelButtonClicked:(EVSearchBar *)searchBar;
- (void)searchBackDoorDidTrigger:(EVSearchBar*)searchBar;

- (BOOL)searchBar:(EVSearchBar*)searchBar invalidInput:(NSString*)text;
- (void)searchBarOnIcon:(EVSearchBar*)searchBar;
@end
